#include <bits/stdc++.h>
using namespace std;
#define int long long
#define val first
#define key second
const int N = 5e5 + 10;
typedef pair<int, int> ppi;

int n, k;

int a[N];
int l[N], r[N];
priority_queue<ppi> q;

void slove()
{
	ppi num;
	do
	{
		num = q.top();
		num.val = -num.val;
		num.key = -num.key;
		q.pop();
	} while (num.val != a[num.key]);

	int prev = l[num.key];
	int next = r[num.key];

	if (prev != -1)
	{
		a[prev] += a[num.key];
		r[prev] = r[num.key];
		q.push({ -a[prev], -prev });
	}

	if (next != -1)
	{
		a[next] += a[num.key];
		l[next] = l[num.key];
		q.push({ -a[next], -next });
	}

	a[num.key] = -1;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	//创建链表
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		l[i] = i - 1;
		r[i] = i + 1;
		q.push({ -a[i], -i });
	}
	l[0] = -1; r[n - 1] = -1;

	while (k--) slove();

	for (int i = 0; i < n; i++)
	{
		if (a[i] != -1)
			cout << a[i] << " ";
	}
	return 0;
}